//
//  EvaluationTeacherViewController.m
//  CommunityNannyO2O
//
//  Created by 90 on 15/7/21.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "EvaluationTeacherViewController.h"
#import "AppConfig.h"
#import "QXNetWorkTool.h"
#import "APIAdress.h"
#import "MBProgressHUD+YC.h"
#import "MJExtension.h"
#import "AccountTool.h"
#import "EvaluationTeacherCell.h"
#import "QXNetWorkTool.h"
#import "UserDataSingleton.h"
#import "EvaluateTipView.h"
#import "SeeTeacherEvaluationModel.h"

@interface EvaluationTeacherViewController()<QXNetWorkToolDelegate,
        UITableViewDataSource,UITableViewDelegate,QXNetWorkToolDelegate,
        EvaluationTeacherDeletage>
{

}

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSString *content;
@end


@implementation EvaluationTeacherViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self configNavigationItem];
    
    self.tableView.dataSource = self;
    
    self.tableView.delegate = self;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //已评价老师
    if ([self.monitor_give_score isEqualToString:@"1"])
    {
        [self seeEvaluation];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 594;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    EvaluationTeacherCell *cell = [EvaluationTeacherCell cellWithTableView:tableView];
    
    cell.teacher_id = self.teacherId;
    cell.exam_id = self.exam_Id;
    
    //已评价老师
    if ([self.monitor_give_score isEqualToString:@"1"])
    {
        cell.content.text = self.content;
        cell.commit.hidden = YES;
    }
    
    cell.delegate = self;
    
    return cell;
}


-(void)configNavigationItem
{
    self.navigationItem.title = @"评价老师";
    [self.navigationController.navigationBar setTranslucent:NO];
    
    [self.navigationController.navigationBar
     setBackgroundImage:[UIImage imageNamed:@"bg_navigation_bar"]
     forBarMetrics:UIBarMetricsDefault];
    
    //status bar的字体为白色
    //导航栏的背景色是黑色
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],NSFontAttributeName,nil]];
    
    [self configNavigationBackAction:^{
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

-(void)useMethodToFindBlackLineAndHind
{
    UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    
    blackLineImageView.hidden = YES;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self configNavigationItem];

    [self useMethodToFindBlackLineAndHind];
}

-(void)GetFailResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    [MBProgressHUD showError:message toView:self.view];
    
}

- (void)GetSuccessMessage:(id)message andTag:(int)tag
{
    NSString *mes = message;
    
    switch (tag)
    {
        case 1:
            
            break;
    }
}


-(void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    if (Response == nil)
    {
        return;
    }
    switch (tag)
    {
        case 1:
        {
            EvaluateTipView *obj = [EvaluateTipView create];
            obj.view.backgroundColor = [UIColor clearColor];
            obj.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            obj.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            obj.definesPresentationContext = YES;

            [self presentViewController:obj animated:YES completion:nil];
            break;
        }
        case 2:
        {
            for (NSDictionary *dic in Response)
            {
                SeeTeacherEvaluationModel *model = [SeeTeacherEvaluationModel SeeTeacherEvaluationWithDict:dic];
                
                self.content = model.give_content;
                
                [self.tableView reloadData];
            }
            break;
        }
    }
}

-(void)commite:(NSString *)teacherId  Content:(NSString *)content
{
    UserDataSingleton *userData = [UserDataSingleton shareInstance];
    if(![userData isLogin])
    {
        [userData pleaseLogin:self];
        return;
    }
    
    if ([content isEqualToString:@""])
    {
        [MBProgressHUD showError:@"请填写评价内容" toView:self.view];
        return;
    }
    
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool *QXnetWorkTool = [[QXNetWorkTool alloc]init];
    
    QXnetWorkTool.QXNetWorkDelegate = self;
    
    [QXnetWorkTool GetDataFromServerWithPostMethodandInterfaceName:EvaluationTeacherInterface andParameter:@[@{@"exam_id":self.exam_Id,@"user_id":userData.user_id , @"teacher_id":teacherId , @"give_content":content}] tag:1];
}

-(void)seeEvaluation
{
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    
    QXNetWorkTool *QXnetWorkTool = [[QXNetWorkTool alloc]init];
    
    QXnetWorkTool.QXNetWorkDelegate = self;
    
    [QXnetWorkTool GetDataFromServerWithPostMethodandInterfaceName:SeeTeacherEvaluationInterface andParameter:@[@{@"exam_id":self.exam_Id}] tag:2];
}

-(void)viewWillDisappear:(BOOL)animated
{

}




@end












